public class Main {
    public static void main(String[] args) {
        System.out.println(new Solution().isSubsequence("abc", "ahbgdc"));
        System.out.println(new Solution().isSubsequence("axc", "ahbgdc"));
    }
}

class Solution {
//    public boolean isSubsequence(String s, String t) {
//        boolean[] dp = new boolean[t.length() + 1];
//        for (int i = 0; i <= t.length(); i++) {
//            dp[i] = true;
//        }
//
//        for (int i = 1; i <= s.length(); i++) {
//            char cs = s.charAt(i - 1);
//            boolean prevDp = dp[0];
//            dp[0] = false;
//            for (int j = 1; j <= t.length(); j++) {
//                char ts = t.charAt(j - 1);
//                boolean temp = dp[j];
//                dp[j] = dp[j - 1] || prevDp && cs == ts;
//                prevDp = temp;
//            }
////            if (i == 1) {
////                dp[0] = false;
////            }
//        }
//        return dp[t.length()];
//    }

    public boolean isSubsequence(String s, String t) {
        int i = 0;
        for (int j = 0; j < t.length() && i < s.length(); j++) {
            if (s.charAt(i) == t.charAt(j)) {
                i++;
            }
        }
        return i == s.length();
    }
}
